package thread.t1;
class P {
	String name = "李四";
	String sex = "女";
}
class Producer implements Runnable {
	P q = null;
	public Producer(P q) {
		this.q = q;
	}
	public void run() {
		int i = 0;
		while (true) {
			if (i == 0) {
				q.name = "张三";
				q.sex = "男";
			} else {
				q.name = "李四";
				q.sex = "女";
			}
			i = (i + 1) % 2;
		}
	}
}
class Consumer implements Runnable {
	P q = null;

	public Consumer(P q) {
		this.q = q;
	}

	public void run() {
		while (true) {
			System.out.println(q.name + " ---->" + q.sex);
		}
	}
}
public class ThreadCommunation1 {
	public static void main(String[] args) {
		P q = new P();
		new Thread(new Producer(q)).start();
		new Thread(new Consumer(q)).start();
	}
}